package com.cph.contentcenter.controller;

import com.cph.contentcenter.dao.content.ShareMapper;
import com.cph.contentcenter.domain.entity.content.Share;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

/**
 * @ClassName TsetController
 * @Description TODO
 * @Author cph
 * @Date 2020/9/25 15:28
 * @Version 1.0
 */
@RestController
public class TestController {

    @Autowired
    private ShareMapper mapper;

    @Autowired
    private DiscoveryClient discoveryClient;

    @GetMapping("/test")
    public List<Share> insert(){
        Share share = new Share();
        share.setCreateTime(new Date());
        share.setUpdateTime(new Date());
        share.setTitle("XXX");
        share.setCover("XXX");
        share.setAuthor("XXX");
        mapper.insertSelective(share);

        return mapper.selectAll();
    }

    @GetMapping("/test2")
    public List<ServiceInstance> setDiscoverClient(){
        //查詢指定服務的實例信息
        return discoveryClient.getInstances("user-center");
    }
}
